
ITEM.base = "base_building"
ITEM.class = "campfire"
ITEM.label = "Campfire"
ITEM.description = "Ready to be lit.*\n\n*Some assembly required."
ITEM.weight = 13
ITEM.model = "models/props_debris/wood_board07a.mdl"
ITEM.icon = "wintersurvival/icon_campfire"
ITEM.lootable = true

//Building

function ITEM:onBuildingInitialize(pl,tab)
	if CLIENT then
		return
	end
	local GM = gmod.GetGamemode()
	
	tab.nextuse = 0
	tab.inventory = {}
	tab.Think = function()
		for class,inv in pairs(tab.inventory) do //class = {quantity,item} format
			if not inv.startburn then
				inv.startburn = CurTime()
			else
				local burnt = inv.item:onBurned(CurTime()-inv.startburn)
				if burnt then //It just got destroyed, remove one at a time
					if type(burnt) == "table" then //New items received! Format: class,qty
						for k,v in pairs(burnt) do
							GM:BuildingGive(tab,k,v)
						end
					elseif burnt then
					end
					inv.startburn = CurTime()
					GM:BuildingGive(tab,class,-1)
				end
			end
		end
	end
	
	wsUID = wsUID + 1
	hook.Add("Think","campfire"..tostring(wsUID),tab.Think)
end

function ITEM:onBuildingUse(pl,tab)
	if CLIENT then
		return
	end
	if CurTime() < tab.nextuse then
		return
	end
	
	local GM = gmod.GetGamemode()
	GM:BuildingUpdate(tab,pl)
	
	tab.nextuse = CurTime() + 1
end
